package mysql

import "gorm.io/gorm"

type CartWeek2 struct {
	gorm.Model
	UserId      int64   `gorm:"type:int(10);comment:用户id;"`
	GoodsId     int64   `gorm:"type:int(10);comment:商品id;"`
	GoodsTitle  string  `gorm:"type:varchar(30);comment:商品标题;"`
	GoodsPrice  float32 `gorm:"type:decimal(10,2);comment:商品价格;"`
	Num         int64   `gorm:"type:int(10);comment:购买数量;"`
	GoodsAvatar string  `gorm:"type:varchar(255);comment:商品图片;"`
}

// 添加购物车
func (c *CartWeek2) CreateCart() error {
	return DB.Create(&c).Error
}

// 购物车列表
func (c *CartWeek2) CartList(userId int) (list []*CartWeek2, err error) {

	err = DB.Where("user_id", userId).Find(&list).Error

	return list, err

}
